package com.tfswue.ershoujiaoyi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tfswue.ershoujiaoyi.entity.Product;
import com.tfswue.ershoujiaoyi.mapper.ProductMapper;
import com.tfswue.ershoujiaoyi.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public Product publish(Product product) {
        productMapper.insert(product);
        return product;
    }

    @Override
    public List<Product> list() {
        return productMapper.selectList(new QueryWrapper<>());
    }

    @Override
    public Product getById(Long id) {
        return productMapper.selectById(id);
    }

    @Override
    public Product update(Product product) {
        productMapper.updateById(product);
        return productMapper.selectById(product.getId());
    }

    @Override
    public boolean delete(Long id) {
        return productMapper.deleteById(id) > 0;
    }
}
